package com.base.myproject.client.HR.bcode;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.busi.BO.TreeNodeModelData;
import com.base.myproject.client.jdbc.DataSet;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.ui.BaseGrid;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.base.myproject.client.ui.celleditor.BaseCheckGroup;
import com.base.myproject.client.ui.celleditor.BaseComboBoxForm;
import com.base.myproject.client.ui.celleditor.BaseComboBoxX;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.ComboBox;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.DateTimePropertyEditor;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.layout.TableData;
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
import com.extjs.gxt.ui.client.widget.toolbar.PagingToolBar;
import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

public class Bcode_Seach extends BaseJDBCPanel{
	
	Button seach  = new Button ("查询");
	Button query = new Button("更多查询");
	Button EXCL  = new Button ("导出EXCEL");
	PagingToolBar toolBar = null;
	List<String> types = null;
	List<String> propertys = null;
	List<String> levels = null;
	BaseComboBoxX bcLeaveReason = new BaseComboBoxX("name", "dictionary",
	"where type = 'hr_leavereason'");
	
	public Bcode_Seach() {
		String sql = "select name,type from dictionary where type='hr_jobtype' union all select name,type from dictionary where type='hr_jobproperty' " +
				"union all select name,type from dictionary where type='zy'";
		final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT.create(com.base.myproject.client.tools.GreetingService.class);
		greetingService2.getDataSet(sql, new AsyncCallback<DataSet>(){
		@Override
			public void onFailure(Throwable caught) {	
			}
			@Override
			public void onSuccess(DataSet result) {  
				types = new ArrayList<String>();
				propertys = new ArrayList<String>();
				levels = new ArrayList<String>();
			    for(int i = 0;i < result.getRowCount();i++){
			    	if(result.getValue(i, "type").equals("hr_jobtype")){
			    		types.add(result.getValue(i, "name"));
			    	}else if(result.getValue(i, "type").equals("hr_jobproperty")){
			    		propertys.add(result.getValue(i, "name"));
			    	}else if(result.getValue(i, "type").equals("zy")){
			    		levels.add(result.getValue(i, "name"));
			    	}
			    }
			    init();
			}
		});
	}

	public void init() {
		initWeigetx();
		registerMainStore(store);
	}
	public void complete() {
		super.complete();
	}
	
	public void initWeigetx(){
		toolBar = new PagingToolBar(10);
		seach.addListener(Events.Select, getListener());
		query.addListener(Events.Select, getListener());
		EXCL.addListener(Events.Select, getListener());
		VerticalPanel vp = new VerticalPanel();
		
		ToolBar queryToolBar = new ToolBar();
		queryToolBar.add(seach);
		queryToolBar.add(EXCL);
		query.setStyleAttribute("paddingLeft", "760px");
		queryToolBar.add(new SeparatorToolItem());
		queryToolBar.add(query);
		ContentPanel panel2 = new ContentPanel();
		panel2.setHeaderVisible(false);
		panel2.setBottomComponent(queryToolBar);
		VerticalPanel sp = new VerticalPanel();
		sp.add(createForm());
		sp.add(createCheckboxForm());
		sp.add(createbestForm());
		panel2.add(sp);
		
		ContentPanel panel = new ContentPanel();
		panel.setHeaderVisible(false);
		panel.add(createGrid());
		panel.setBottomComponent(toolBar);

		vp.add(panel2);
		vp.add(panel);
		
		vp.setSpacing(5);
		add(vp);
		this.layout();
	}
	
	FormPanel form  = null;
	
	DepartmentSelectDialog<TreeNodeModelData> s_dep ;//多选部门
	BaseComboBoxX jibie;//级别
	TextField<String> s_bcode;
	TextField<String> s_name;
	BaseComboBoxX s_sex;
	TextField<String> s_zw;
	TextField<String> p_card_num;

	DateField bgin_rzrq = new DateField();
	DateField end_rzrq = new DateField();
	DateField bgin_jtrzrq = new DateField();
	DateField end_jtrzrq = new DateField();
	DateField bgin_zzrq = new DateField();
	DateField end_zzrq = new DateField();
	DateField bgin_zhgzrq = new DateField();
	DateField end_zhgzrq = new DateField();
	DateField bgin_csrq = new DateField();
	DateField end_csrq = new DateField();
	DateField bgin_qzyxrq = new DateField();
	DateField end_qzyxrq = new DateField();
	
	NumberField begin_age = new NumberField();
	NumberField end_age = new NumberField();
	
	
	TextField<String> s_country;
	
	BaseComboBoxX mery;
	
	DateField bgin_zhtxrq = new DateField();
	DateField end_zhtxrq = new DateField();
	NumberField bgin_gznxrq = new NumberField();
	NumberField end_gznxrq= new NumberField();
	DateField bgin_lzrq = new DateField();
	DateField end_lzrq= new DateField();
	DateField bgin_birthday = new DateField();
	DateField end_birthday= new DateField();
	BaseComboBoxX hr_Census_Province;
	BaseComboBoxX hr_Census_city;
	BaseComboBoxX hr_Census_area;
	BaseComboBoxX hr_City_Township;
	ComboBox<ModelData> status;
	/*******************/
	
	private FormPanel mform;
	private FormPanel createForm(){
		mform= new FormPanel();
	
		TableLayout tl = new TableLayout(8);
		
		mform.setWidth(913);
		mform.setPadding(4);
		mform.setBodyBorder(false);
		TableData td = new TableData();
		td.setRowspan(1);
		td.setHorizontalAlign(HorizontalAlignment.LEFT);
		td.setVerticalAlign(VerticalAlignment.TOP);
		td.setPadding(2);
		
		TableData td2 = new TableData();
		td2.setRowspan(1);
		td2.setColspan(7);
		td2.setHorizontalAlign(HorizontalAlignment.LEFT);
		td2.setVerticalAlign(VerticalAlignment.TOP);
		td2.setPadding(2);
		
		mform.setLayout(tl);
		mform.setHeaderVisible(false);
	
		
		
		mform.add(new Label("雇用编码:"), td);
		s_bcode  = new TextField<String>(); 
		s_bcode.setWidth(127);
		s_bcode.setName("bcode");
		mform.add(s_bcode,td);
		
		mform.add(new Label("姓名:"), td);
		s_name  = new TextField<String>(); 
		s_name.setWidth(127);
		s_name.setName("name");
		mform.add(s_name,td);
		
		mform.add(new Label("性别:"), td);
		s_sex  =  new BaseComboBoxX("name", "dictionary", "where type='hr_sex'");
		s_sex.setWidth(127);
		mform.add(s_sex,td);
		
		mform.add(new Label("职位:"), td);
		s_zw  = new TextField<String>(); 
		s_zw.setWidth(127);
		s_zw.setName("zw");
		mform.add(s_zw,td);
		
		mform.add(new Label("部门:"), td);
		s_dep = new DepartmentSelectDialog<TreeNodeModelData>(){
			public void doposted(List<TreeNodeModelData> modeldatalist) {
				if(modeldatalist.size() > 0){
					String bcode_str="";
					for(int i = 0; i < modeldatalist.size();i++){
						bcode_str = bcode_str + ";" + modeldatalist.get(i).get("name");
					}
					bcode_str = bcode_str.substring(1, bcode_str.length());
					this.setEmptyText(bcode_str);
				}
			}
		};
		s_dep.setNeesreselect(false);
		s_dep.setEmptyText("未选择数据");
		s_dep.setWidth(127);
		mform.add(s_dep,td);
		
		mform.add(new Label("雇佣状态："),td);
		status = new ComboBox<ModelData>();
		ListStore<ModelData> liststore = new ListStore<ModelData>();
		ModelData model = new BaseModelData();
		model.set("value", 0);
		model.set("name", "在职");
		liststore.add(model);
		
		ModelData model2 = new BaseModelData();
		model2.set("value", 1);
		model2.set("name", "离职");
		liststore.add(model2);
		status.setStore(liststore);
		status.setDisplayField("name");
		status.setValue(model);
		status.setWidth(127);
		status.setTriggerAction(ComboBox.TriggerAction.ALL);
		mform.add(status,td);
		
		mform.add(new Label("入职日期:"), td);//ddd
		bgin_rzrq.setWidth(127);
		bgin_rzrq.setPropertyEditor(new DateTimePropertyEditor("yyyy-MM-dd"));
		mform.add(bgin_rzrq,td);
		mform.add(new Label("至:"), td);
		end_rzrq.setWidth(127);
		end_rzrq.setPropertyEditor(new DateTimePropertyEditor("yyyy-MM-dd"));
		mform.add(end_rzrq,td);
		
		mform.add(new Label("离职日期:"), td);
		bgin_lzrq.setWidth(127);
		bgin_lzrq.setPropertyEditor(new DateTimePropertyEditor("yyyy-MM-dd"));
		mform.add(bgin_lzrq,td);
		mform.add(new Label("至:"), td);
		end_lzrq.setWidth(127);
		end_lzrq.setPropertyEditor(new DateTimePropertyEditor("yyyy-MM-dd"));
		mform.add(end_lzrq,td);
		
		mform.add(new Label("工作年限:"), td);
		mform.add(bgin_gznxrq,td);
		bgin_gznxrq.setWidth(127);
		mform.add(new Label("至:"), td);
		mform.add(end_gznxrq,td);
		end_gznxrq.setWidth(127);
		
		mform.add(new Label("年龄从:"), td);
		mform.add(begin_age,td);
		begin_age.setWidth(127);
		mform.add(new Label("至:"), td);
		mform.add(end_age,td);
		end_age.setWidth(127);
		return mform;
	};
	
	BaseCheckGroup checkBox2 = null;
	BaseCheckGroup checkBox3 = null;
	BaseCheckGroup checkBox4 = null;
	
	/**
	 * @return
	 */
	private FormPanel formpanel = null;
	private FormPanel createCheckboxForm(){
		formpanel = new FormPanel();
		TableLayout tl = new TableLayout(2);
		formpanel.setWidth(913);
		formpanel.setPadding(4);
		formpanel.setBodyBorder(false);
		
		TableData td = new TableData();
		td.setHorizontalAlign(HorizontalAlignment.LEFT);
		td.setVerticalAlign(VerticalAlignment.TOP);
		
		formpanel.setLayout(tl);
		formpanel.setHeaderVisible(false);
	
		formpanel.add(new Label("工作种类:"), td);
		BaseCheckGroup checkBox = new BaseCheckGroup(new String[]{"无"});
		checkBox.setHeight(25);
		formpanel.add(checkBox,td);
		
		formpanel.add(new Label("工作类别:"), td);
		String [] type = types.toArray(new String[types.size()]);
		checkBox2 = new BaseCheckGroup(type,true);
		checkBox2.setHeight(25);
		formpanel.add(checkBox2,td);
		
		formpanel.add(new Label("工作性质:"), td);
		String [] property = propertys.toArray(new String[propertys.size()]);
		checkBox3 = new BaseCheckGroup(property,true);
		checkBox3.setHeight(25);
		formpanel.add(checkBox3,td);
		
		formpanel.add(new Label("雇佣级别："),td);
		String [] level = levels.toArray(new String[levels.size()]);
		checkBox4 = new BaseCheckGroup(level,true);
		checkBox4.setHeight(25);
		formpanel.add(checkBox4,td);
		
		formpanel.setAnimCollapse(true);
		formpanel.setCollapsible(true);
		formpanel.setDeferHeight(true);
		formpanel.setExpanded(false);
		
		return formpanel;
	}
	FormPanel createbestForm(){
		form = new FormPanel();
		TableLayout tl = new TableLayout(8);
		form.setWidth(913);
		form.setPadding(4);
		form.setBodyBorder(false);
		
		TableData td = new TableData();
		td.setRowspan(1);
		td.setHorizontalAlign(HorizontalAlignment.LEFT);
		td.setVerticalAlign(VerticalAlignment.TOP);
		td.setPadding(2);
		
		TableData td2 = new TableData();
	//	td2.setRowspan(4);
		td2.setColspan(4);
		td2.setHorizontalAlign(HorizontalAlignment.LEFT);
		td2.setVerticalAlign(VerticalAlignment.TOP);
		td2.setPadding(2);
		
		form.setLayout(tl);
		form.setHeaderVisible(false);
	
		
		
		form.add(new Label(""), td2);
		form.add(new Label(""), td2);
		
		form.add(new Label("集团入职日期:"), td);
		bgin_jtrzrq.setWidth(127);
		bgin_jtrzrq.setPropertyEditor(new DateTimePropertyEditor("yyyy-MM-dd"));
		form.add(bgin_jtrzrq,td);
		form.add(new Label("至:"), td);
		end_jtrzrq.setWidth(127);
		end_jtrzrq.setPropertyEditor(new DateTimePropertyEditor("yyyy-MM-dd"));
		form.add(end_jtrzrq,td);
		
		form.add(new Label("最后工作日期:"), td);
		bgin_zhgzrq.setWidth(127);
		bgin_zhgzrq.setPropertyEditor(new DateTimePropertyEditor("yyyy-MM-dd"));
		form.add(bgin_zhgzrq,td);
		form.add(new Label("至:"), td);
		end_zhgzrq.setWidth(127);
		end_zhgzrq.setPropertyEditor(new DateTimePropertyEditor("yyyy-MM-dd"));
		form.add(end_zhgzrq,td);
		
		form.add(new Label("婚姻状况:"), td);
		mery  =  new BaseComboBoxX("name", "dictionary", "where type='hr_marry'");
		mery.setWidth(127);
		form.add(mery,td);
		
		form.add(new Label("国籍:"), td);
		s_country  = new TextField<String>(); 
		s_country.setWidth(127);
		form.add(s_country,td);
		
		form.add(new Label("户籍省份:"), td);
		hr_Census_Province = new BaseComboBoxX("name","dictionary", "where type='hr_p'");
		hr_Census_Province.setWidth(127);
		form.add(hr_Census_Province,td);
		
		form.add(new Label("户籍市:"), td);
	    hr_Census_city = new BaseComboBoxX("name","dictionary", "where type='hr_c'");
	    hr_Census_city.setWidth(127);
		form.add(hr_Census_city,td);
		
		form.add(new Label("户籍区:"), td);
	    hr_Census_area = new BaseComboBoxX("name","dictionary", "where type='hr_a'");
	    hr_Census_area.setWidth(127);
		form.add(hr_Census_area, td);
		
		form.add(new Label("城/乡:"), td);
		hr_City_Township = new BaseComboBoxX("name","dictionary", "where type='hr_cz'");
		hr_City_Township.setWidth(127);
		form.add(hr_City_Township, td);
		
		form.add(new Label("省份证号码:"), td);
		p_card_num  = new TextField<String>(); 
		p_card_num.setWidth(127);
		//p_card_num.setName("p_card");
		form.add(p_card_num,td);
		
		form.add(new Label("状况:"), td);
		TextField<String> zk  = new TextField<String>(); 
		zk.setWidth(127);
		form.add(zk,td);
		
		form.add(new Label("最后调薪日期:"), td);
		bgin_zhtxrq.setWidth(127);
		bgin_zhtxrq.setPropertyEditor(new DateTimePropertyEditor("yyyy-MM-dd"));
		form.add(bgin_zhtxrq,td);
		form.add(new Label("至:"), td);
		end_zhtxrq.setWidth(127);
		end_zhtxrq.setPropertyEditor(new DateTimePropertyEditor("yyyy-MM-dd"));
		form.add(end_zhtxrq,td);
		
		
		form.add(new Label("签证有效日期:"), td);
		bgin_qzyxrq.setWidth(127);
		bgin_qzyxrq.setPropertyEditor(new DateTimePropertyEditor("yyyy-MM-dd"));
		form.add(bgin_qzyxrq,td);
		form.add(new Label("至:"), td);
		end_qzyxrq.setWidth(127);
		end_qzyxrq.setPropertyEditor(new DateTimePropertyEditor("yyyy-MM-dd"));
		form.add(end_qzyxrq,td);
		
		form.add(new Label("出生日期:"), td);
		bgin_csrq.setWidth(127);
		bgin_csrq.setPropertyEditor(new DateTimePropertyEditor("yyyy-MM-dd"));
		form.add(bgin_csrq,td);
		form.add(new Label("至:"), td);
		end_csrq.setWidth(127);
		end_csrq.setPropertyEditor(new DateTimePropertyEditor("yyyy-MM-dd"));
		form.add(end_csrq,td);
	
		form.add(new Label("转正日期:"), td);
		bgin_zzrq.setWidth(127);
		bgin_zzrq.setPropertyEditor(new DateTimePropertyEditor("yyyy-MM-dd"));
		form.add(bgin_zzrq,td);
		form.add(new Label("至:"), td);
		end_zzrq.setWidth(127);
		end_zzrq.setPropertyEditor(new DateTimePropertyEditor("yyyy-MM-dd"));
		form.add(end_zzrq,td);
		
		form.add(new Label("生日:"), td);
		bgin_birthday.setWidth(127);
		bgin_birthday.setPropertyEditor(new DateTimePropertyEditor("MM-dd"));
		form.add(bgin_birthday,td);
		form.add(new Label("至:"), td);
		end_birthday.setWidth(127);
		end_birthday.setPropertyEditor(new DateTimePropertyEditor("MM-dd"));
		form.add(end_birthday,td);
		
		form.add(new Label("雇佣工作调整记录:"), td);
		TextField<String> zttk  = new TextField<String>(); 
		zttk.setWidth(127);
		form.add(zttk,td);
		
		form.add(new Label("离职原因:"), td);
		bcLeaveReason.setWidth(127);
		form.add(bcLeaveReason,td);
		
		form.setAnimCollapse(true);
		form.setCollapsible(true);
		form.setDeferHeight(true);
		form.addListener(Events.Collapse, new Listener<BaseEvent>() {
			@Override
			public void handleEvent(BaseEvent be) {
				grid.setHeight(350);
			}
		});

		form.addListener(Events.Expand, new Listener<BaseEvent>() {
			@Override
			public void handleEvent(BaseEvent be) {
				grid.setHeight(200);
			}
		});
		form.setExpanded(false);
		return form;
	};
		
	private BaseStore<BusiObject> store = null;
	
	public BaseStore<BusiObject> getStore(){
		if(store == null){
			createStore();
		}
		store.setToolBar(toolBar);
		store.initcompleted();
		return store;
	} 
	
	private BaseStore<BusiObject> createStore(){
		ModelType type = new ModelType();
		
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		
		type.addField("bcode");
		type.addField("bname");
		type.addField("hr_name_Alias");
		type.addField("hr_firstname_en");
		type.addField("sex");
		type.addField("hr_Marital_status");
		type.addField("up_department");
		type.addField("systemid");
		type.addField("entrydate");
		type.getField("entrydate").setType(Date.class);
		type.addField("employoutertitle");
		type.addField("leavereason");
		type.addField("employinnertitle");
		type.addField("jobtype");
		type.addField("jobproperty");
		type.addField("employno");
		type.addField("Resignationdate");
		type.getField("Resignationdate").setType(Date.class);
		type.addField("hr_nationality");
		type.addField("contractstartdate");
		type.getField("contractstartdate").setType(Date.class);
		type.addField("contractsenddate");
		type.getField("contractsenddate").setType(Date.class);
		type.addField("employlevel");
		type.addField("groupregularizationdate");
		type.getField("groupregularizationdate").setType(Date.class);
		type.addField("Insurancedate");
		type.getField("Insurancedate").setType(Date.class);
		type.addField("attendancecardno");
		type.addField("idNo");
		type.addField("hr_idcard_addr");
		type.addField("age");
		type.addField("employstatus");
		type.addField("hr_Census_city");
		type.addField("hr_City_Township");
		type.addField("hostelno");
		type.addField("lockersno");
		type.addField("basesalary");
		type.addField("hr_bankcard");
		type.addField("hr_bankno");
		type.addField("Regularizationdate");
		type.getField("Regularizationdate").setType(Date.class);
		type.addField("hr_status");
		type.addField("lastpaydate");
		type.getField("lastpaydate").setType(Date.class);
		type.addField("lastjobdate");
		type.getField("lastjobdate").setType(Date.class);
		type.addField("hr_idcard_limitdate");
		type.getField("hr_idcard_limitdate").setType(Date.class);
		type.addField("syalsry_startdate");
		type.getField("syalsry_startdate").setType(Date.class);
		type.addField("bird");
		type.getField("bird").setType(Date.class);
		
		StoreInfo info = new StoreInfo();
		info.setSql("select * from bcode where 1=2");
		store = new BaseStore<BusiObject>(type, info);
		return store;
	}
	
	private BaseGrid<ModelData> grid = null;
	
	private BaseGrid<ModelData> createGrid(){
		CheckBoxSelectionModel<ModelData> cbs = new CheckBoxSelectionModel<ModelData>();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());
		
		ColumnConfig C16 = new ColumnConfig("employno", "雇员编码", 80);
		columns.add(C16);
		ColumnConfig C18 = new ColumnConfig("bname", "雇员中文姓名", 80);
		columns.add(C18);
		ColumnConfig C1 = new ColumnConfig("hr_name_Alias", "別名", 80);
		C1.setHidden(true);
		columns.add(C1);
		ColumnConfig C17 = new ColumnConfig("hr_firstname_en", "雇员英文姓名", 80);
		columns.add(C17);
		ColumnConfig C3 = new ColumnConfig("sex", "性别", 80);
		columns.add(C3);
		ColumnConfig age = new ColumnConfig("age", "年龄", 40);
		columns.add(age);
		ColumnConfig employstatus = new ColumnConfig("employstatus", "雇佣状态", 60);
		columns.add(employstatus);
		
		ColumnConfig C40 = new ColumnConfig("bird", "出生日期", 80);
		C40.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		columns.add(C40);
		
		ColumnConfig C31 = new ColumnConfig("entrydate", "入职日期", 80);
		C31.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		columns.add(C31);
		
		ColumnConfig C25 = new ColumnConfig("hr_Marital_status", "婚姻状况", 80);
		columns.add(C25);
		
		ColumnConfig C2 = new ColumnConfig("up_department", "部门", 80);
		BaseComboBoxForm<BaseModelData> bsb1 = new BaseComboBoxForm<BaseModelData>("id","name","systeminfo","",true);
		bsb1.setReadOnly(true);
		C2.setRenderer(bsb1);
		C2.setEditor(bsb1.getCelEditor());
		columns.add(C2);
		
		ColumnConfig C5 = new ColumnConfig("systemid", "分部门", 80);
		BaseComboBoxForm<BaseModelData> bsb2 = new BaseComboBoxForm<BaseModelData>("id","name","systeminfo","",true);
		bsb2.setReadOnly(true);
		C5.setRenderer(bsb2);
		C5.setEditor(bsb2.getCelEditor());
		columns.add(C5);
		
		ColumnConfig C43 = new ColumnConfig("employinnertitle", "职位", 80);
		C43.setHidden(true);
		columns.add(C43);
		
		ColumnConfig C9 = new ColumnConfig("jobtype", "工作类别(中文)", 80);
		C9.setHidden(true);
		columns.add(C9);
		
		ColumnConfig C13 = new ColumnConfig("jobproperty", "工作性质(中文)", 80);
		C13.setHidden(true);
		columns.add(C13);
		
		ColumnConfig C14 = new ColumnConfig("jobgroup", "工作组别(中文)", 80);
		C14.setHidden(true);
		columns.add(C14);
		
		ColumnConfig C4 = new ColumnConfig("Resignationdate", "辞职有效日期", 80);
		C4.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		C4.setHidden(true);
		columns.add(C4);
		
		ColumnConfig C19 = new ColumnConfig("hr_nationality", "国籍", 80);
		C19.setHidden(true);
		columns.add(C19);
		
		ColumnConfig C20 = new ColumnConfig("contractstartdate", "合约生效日期", 80);
		C20.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		C20.setHidden(true);
		columns.add(C20);
		
		ColumnConfig C21 = new ColumnConfig("contractsenddate", "合约终止日期", 80);
		C21.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		C21.setHidden(true);
		columns.add(C21);
		
		ColumnConfig C26 = new ColumnConfig("employlevel", "级别名称(中文)", 80);
		C26.setHidden(true);
		columns.add(C26);
		
		ColumnConfig C27 = new ColumnConfig("groupregularizationdate", "集团入职日期", 80);
		C27.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		C27.setHidden(true);
		columns.add(C27);
		
		ColumnConfig C28 = new ColumnConfig("Insurancedate", "减保日期", 80);
		C28.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		C28.setHidden(true);
		columns.add(C28);
		
		ColumnConfig C29 = new ColumnConfig("attendancecardno", "考勤卡号码", 80);
		C29.setHidden(true);
		columns.add(C29);
		
		ColumnConfig C32 = new ColumnConfig("idNo", "身份证编码", 140);
		columns.add(C32);
		
		ColumnConfig C33 = new ColumnConfig("hr_idcard_addr", "身份证地址", 120);
		C33.setHidden(true);
		columns.add(C33);
		
		ColumnConfig C35 = new ColumnConfig("hr_Census_city", "市", 80);
		C35.setHidden(true);
		columns.add(C35);
		
		ColumnConfig C36 = new ColumnConfig("hostelno", "宿舍号码", 80);
		C36.setHidden(true);
		columns.add(C36);
		
		ColumnConfig C37 = new ColumnConfig("lockersno", "更衣柜号码", 80);
		C37.setHidden(true);
		columns.add(C37);
		
		ColumnConfig C38 = new ColumnConfig("basesalary", "薪金", 80);
		C38.setHidden(true);
		columns.add(C38);
		
		ColumnConfig C41 = new ColumnConfig("hr_bankcard", "银行账户号码", 120);
		C41.setHidden(true);
		columns.add(C41);
		
		ColumnConfig C42 = new ColumnConfig("hr_bankno", "银行中文名称", 80);
		C42.setHidden(true);
		columns.add(C42);
		
		ColumnConfig C45 = new ColumnConfig("Regularizationdate", "转正日期", 80);
		C45.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		C45.setHidden(true);
		columns.add(C45);
		
		ColumnConfig C46 = new ColumnConfig("hr_status", "状况", 80);
		C46.setHidden(true);
		columns.add(C46);
		
		ColumnConfig C52 = new ColumnConfig("hr_City_Township", "城乡", 80);
		C52.setHidden(true);
		columns.add(C52);
		
		ColumnConfig C47 = new ColumnConfig("lastpaydate", "最后付款日期", 80);
		C47.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		C47.setHidden(true);
		columns.add(C47);
		
		ColumnConfig C48 = new ColumnConfig("lastjobdate", "最后工作日期", 80);
		C48.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		C48.setHidden(true);
		columns.add(C48);
		
		ColumnConfig C49 = new ColumnConfig("hr_idcard_limitdate", "身份证过期日期", 80);
		C49.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		C49.setHidden(true);
		columns.add(C49);
		
		ColumnConfig C50 = new ColumnConfig("syalsry_startdate", "最后调薪日期", 80);
		C50.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		C50.setHidden(true);
		columns.add(C50);
		
		ColumnConfig C51 = new ColumnConfig("leavereason", "离职原因", 80);
		C51.setHidden(true);
		columns.add(C51);
	
		ColumnModel cm = new ColumnModel(columns);
		grid = new BaseGrid<ModelData>(getStore(), cm,false,false);
		grid.setLoadMask(true);
		cbs.setSelectionMode(SelectionMode.SINGLE);
		grid.setSelectionModel(cbs);
		grid.setBorders(false);
	
		grid.setHeight(280);
		grid.setWidth(953);
		return grid ;
	}
	
	int sync = 0;
	Listener<BaseEvent> defaultlistener;
	Listener<BaseEvent> getListener() {
		if (defaultlistener != null) {
			return defaultlistener;
		}
		defaultlistener = new Listener<BaseEvent>() {
			public void handleEvent(BaseEvent be) {
				sync++;
			
				try {
					if (sync == 1) {
						if (be.getType() == Events.Select) {
							if(be.getSource().equals(seach)){
								get_seach();
							}else if(be.getSource().equals(EXCL)){
								Export_excel();
							}else if(be.getSource().equals(query)){
								form.setExpanded(!form.isExpanded());
								formpanel.setExpanded(!formpanel.isExpanded());
							}
						}else if (be.getType() == Events.OnClick) {
							
						} else if (be.getType() == Events.Change) {
							
						}
						else if(be.getType().equals(Events.RowDoubleClick))
						{	
						}else if (be.getType() == Events.KeyUp) {
							if (be instanceof ComponentEvent) {
								if (((ComponentEvent) be).getKeyCode() == 13) // 回车
								{
									get_seach();
								}
							}
						}
					}
				} finally {
					sync--;
				}
			}
		};
		return defaultlistener;
	}	
	
	/**
	 * 处理如入查询的条件  组合sql条件  并给grid  setsql
	 */
	String where = "";
	public void get_seach(){//
		where = "where 1=1 ";
		boolean bbl=true; //用于控制用户在什么都没有输入的时候判断
		if (s_bcode.getValue() != null) {//bcode  雇员编码条件
			where += " and ( bcode_job.employno like '%25"+s_bcode.getRawValue()+ "%25') ";
			bbl=false;
		}
		if (s_name.getValue() != null) {//bcode   姓名条件
			where += " and bcode.bname like '%25"+ s_name.getRawValue() + "%25'";
			bbl=false;
		}
		if (s_sex.getValue() != null) {//bcode    性别条件
			where += " and bcode.sex = '"+s_sex.getValue().get("value")+"'";
			bbl=false;
		}
		//职位
		if (!s_zw.getRawValue().equals("")) {//bcode_job  
			where += " and bcode_job.employinnertitle like '%25"+ s_zw.getRawValue() + "%25'";
			bbl=false;
		}
		if (!bcLeaveReason.getRawValue().equals("")) {//离职原因
			where += " and bcode_job.leavereason = '"+ bcLeaveReason.getRawValue() + "'";
			bbl=false;
		}
		//部门   ddd
		List<TreeNodeModelData>  selectchecklist = s_dep.getTree().getCheckedSelection();
		String dep_str = "";
		for(TreeNodeModelData tnmd : selectchecklist){
			dep_str += " systemid like '" + tnmd.get("systemid") + "%25' or";
		}
		if(dep_str.length() > 0){
			dep_str = dep_str.substring(0, dep_str.length() - 2);
			where += " and ("+dep_str+")";
			bbl = false;
		}
		
		//雇佣状态
		if(!status.getRawValue().equals("")){
			where += " and bcode_job.employstatus='"+status.getRawValue()+"'";
			bbl = false;
		}
		
		//入职日期  bcode_job:entrydate
		if(!bgin_rzrq.getRawValue().equals("")){
			where += "  and bcode_job.entrydate  >= '"+ bgin_rzrq.getRawValue()+ "'";
			bbl=false;
		}
		
		if(!end_rzrq.getRawValue().equals("")){
			where += "  and bcode_job.entrydate  <= '"+ end_rzrq.getRawValue()+ "'";
			bbl=false;
		}
		
		//转正日期
		if(!bgin_zzrq.getRawValue().equals("") && !end_zzrq.getRawValue().equals("")){
			where += "  and bcode_job.Regularizationdate  BETWEEN '"+ bgin_zzrq.getRawValue()+ "' and '"+end_zzrq.getRawValue()+"' ";
			bbl=false;
		}
		//离职日期
		if(!bgin_lzrq.getRawValue().equals("") && !end_lzrq.getRawValue().equals("")){
			where += "  and bcode_job.Resignationdate BETWEEN '"+ bgin_lzrq.getRawValue()+ "' and '"+end_lzrq.getRawValue()+"' ";
			bbl=false;
		}
		
		
		
		//工作种类待定
		//todo
		
		// 雇佣级别
		if (checkBox4.getValueArray().length > 0) {
			String str1 = " and bcode_job.employlevel in (";
			String str2 = "";
			boolean bl = false;
			for(int i = 0;i < checkBox4.getValueArray().length;i++){
				bl = true;
				String value = (String)checkBox4.getValueArray()[i];
				str2 += "'" + value + "',";
			}
			if(bl){
				str2 = str2.substring(0, str2.length() - 1);
				where += str1 + str2 + ")";
				bbl = false;
			}
		}
		
		//工作类别
		if (checkBox2.getValueArray().length > 0) {//bcode_job
			String str1 = " and bcode_job.jobtype in (";
			String str2 = "";
			boolean bl = false;
			for(int i = 0;i < checkBox2.getValueArray().length;i++){
				bl = true;
				String value = (String)checkBox2.getValueArray()[i];
				str2 += "'" + value + "',";
			}
			if(bl){
				str2 = str2.substring(0, str2.length()-1);
				where += str1 + str2 + ") ";
				bbl=false;
			}
		}
		//工作 性质   
		if (checkBox3.getValueArray().length > 0) {//bcode_job
			String str1 = " and bcode_job.jobproperty in (";
			String str2 = "";
			boolean bl = false;
			for(int i = 0;i < checkBox3.getValueArray().length;i++){
				bl = true;
				String value = (String)checkBox3.getValueArray()[i];
				str2 += "'" + value + "',";
			}
			if(bl){
				str2 = str2.substring(0, str2.length()-1);
				where += str1 + str2 +") ";
				bbl = false;
			}
		}
		
        //集团入职日期
		if(!bgin_jtrzrq.getRawValue().equals("") && !end_jtrzrq.getRawValue().equals("")){
			where += "  and bcode_job.groupregularizationdate  BETWEEN '"+ bgin_jtrzrq.getRawValue()+ "' and '"+end_jtrzrq.getRawValue()+"' ";
			bbl=false;
		}
		
		//最后工作日期
		if(!bgin_zhgzrq.getRawValue().equals("") && !end_zhgzrq.getRawValue().equals("")){
			where += "  and bcode_job.lastjobdate  BETWEEN '"+ bgin_zhgzrq.getRawValue()+ "' and '"+end_zhgzrq.getRawValue()+"' ";
			bbl=false;
		}
		//婚姻状况
		if(!mery.getRawValue().equals("")){
			where += "  and bcode.hr_Marital_status ='"+ mery.getRawValue()+ "'";
			bbl=false;
		}
		//国籍
		if(!s_country.getRawValue().equals("")){
			where += "  and bcode.hr_nationality like '%25"+ s_country.getRawValue()+ "%25'";
			bbl=false;
		}
		
		//户籍省
		if(!hr_Census_Province.getRawValue().equals("")){
			where += "  and bcode.hr_Census_Province = '"+ hr_Census_Province.getRawValue()+ "'";
			bbl=false;
		}
		//户籍市
		if(!hr_Census_city.getRawValue().equals("")){
			where += "  and bcode.hr_Census_city = '"+ hr_Census_city.getRawValue()+ "'";
			bbl=false;
		}
		//户籍区
		if(!hr_Census_area.getRawValue().equals("")){
			where += "  and bcode.hr_Census_area = '"+ hr_Census_area.getRawValue()+ "'";
			bbl=false;
		}
		//城镇/农村
		if(!hr_City_Township.getRawValue().equals("")){
			where += "  and bcode.hr_City_Township = '"+ hr_City_Township.getRawValue()+ "'";
			
		}
		//身份证号码   ddd
		if (!p_card_num.getRawValue().equals("")) {//bcode_job  
			where +="and bcode.bcode in (select bcode from hr_idCard where type='身份证' and idNo like '%25"+p_card_num.getRawValue()+"%25')";
			bbl=false;
		}
		//最后调薪日期
		if (!bgin_zhtxrq.getRawValue().equals("") && !end_zhtxrq.getRawValue().equals("")) {//bcode_job  
			where +=" and bcode.bcode in (select bcode from  bcode_Allowance   where status = '0' and startdate  between '"+bgin_zhtxrq.getRawValue()+"' and '"+end_zhtxrq.getRawValue()+"' group by bcode )";
			bbl=false;
		}
		//签证有效日期
		if (!bgin_qzyxrq.getRawValue().equals("") && !end_qzyxrq.getRawValue().equals("")) {//bcode_job  
			where +=" and bcode.bcode in (select bcode from  hr_idCard  where passAvailableDate  between '"+bgin_qzyxrq.getRawValue()+"' and '"+bgin_qzyxrq.getRawValue()+"' and type='护照' group by bcode) ";
			bbl=false;
		}
		//出生日期
		if(!bgin_csrq.getRawValue().equals("") && !end_csrq.getRawValue().equals("")){
			where += "  and bcode.bird  BETWEEN '"+ bgin_csrq.getRawValue()+ "' and '"+end_csrq.getRawValue()+"' ";
			bbl=false;
		}
		//生日
		if(!bgin_birthday.getRawValue().equals("") && !end_birthday.getRawValue().equals("")){
			where += "  and convert(varchar(4), getdate(), 120) %2B substring(convert(varchar(10), bird, 120),5,10)  BETWEEN convert(varchar(4), getdate(), 120) %2B '" + "-"
				+ bgin_birthday.getRawValue()+ "' and convert(varchar(4), getdate(), 120) %2B '" + "-" + end_birthday.getRawValue() + "' ";
			bbl=false;
		}
		//工作年限
		if (!bgin_gznxrq.getRawValue().equals("") && !end_gznxrq.getRawValue().equals("")) {//bcode_job  
			where +=" and bcode_job.Work_experience BETWEEN  "+bgin_gznxrq.getRawValue()+" and "+end_gznxrq.getRawValue();
			bbl=false;
		}
		//年龄
		if (!begin_age.getRawValue().equals("")) {
			where +=" and bcode.age >=  "+begin_age.getRawValue();
			bbl=false;
		}
		if (!end_age.getRawValue().equals("")) {
			where += " and bcode.age <= " + end_age.getRawValue();
			bbl=false;
		}
		
		if(bbl){
			MessageBox.alert("提示信息", "您还没有输入任何查询条件！",null);
			return;
		}
		String sq="select  bcode.age, bcode_job.employstatus, bcode.icode, bcode_job.leavereason, bcode.hr_City_Township, bcode.hr_name_Alias,bcode.bird,bcode.up_department,bcode.departments,bcode.sex ," +
		"bcode_job.Resignationdate, bcode_job.employinnertitle,bcode.systemid,bcode_job.jobtype," +
		"bcode_job.jobproperty,bcode_job.jobgroup,bcode.bcode," +
		"bcode.hr_firstname_en,bcode.bname,bcode.hr_nationality," +
		"hr_bcode_contract.contract_begin_date contractstartdate,hr_bcode_contract.contract_end_date contractsenddate," +
		"bcode.hr_Marital_status,bcode_job.employlevel,bcode_job.groupregularizationdate,bcode_job.Insurancedate," +
		"bcode_job.attendancecardno,bcode_job.entrydate,(select top 1 addr  from hr_idCard  where type='身份证' and bcode=bcode.bcode)" +
		" as hr_idcard_addr,(select top 1 idNo  from hr_idCard  where type='身份证' and bcode=bcode.bcode) as idNo," +
		"bcode.hr_Census_Province,bcode.hr_Census_city,bcode_job.hostelno," +
		"bcode_job.lockersno,bcode.basesalary,bcode.hr_bankcard,bcode.hr_bankno," +
		"bcode_job.employoutertitle,bcode_job.Regularizationdate,bcode.hr_status," +
		"bcode_job.lastpaydate,bcode_job.lastjobdate,(select top 1 availableDate  from hr_idCard  where type='身份证' and bcode=bcode.bcode) as hr_idcard_limitdate," +
		"bcode_job.employno,(select top 1 startdate from bcode_Allowance where bcode=bcode.bcode and no_ ='A01' and status=0 order by startdate desc)" +
		" as  syalsry_startdate,'ff' as m7 " +
		" from bcode left join bcode_job on bcode.bcode=bcode_job.bcode  left join (select * from hr_bcode_contract a where exists (select 1 from hr_bcode_contract where bcode = a.bcode group by bcode having max(contract_begin_date) = a.contract_begin_date)) as hr_bcode_contract on bcode.bcode = hr_bcode_contract.bcode "+where;
		
		grid.getStore().getStoreinfo().setSql(sq);
		grid.getStore().reload();
		grid.getView().refresh(true);
	}
	
	public  void Export_excel(){
//		ExcelObject eo  = Grid2ExcelBO.getInstance().getEO(grid);
//		DownExcelDialog.getInstance().javascript(eo);
		if(where.equals("")){
			MessageBox.alert("提示", "请先查询以后再选择导出到Excel", null);
		}else{
			ColumnModel com = grid.getColumnModel();
			int config = com.getColumnCount();
			List<ColumnConfig> columnconfigs = new ArrayList<ColumnConfig>();
			for(int i = 0;i < config;i++){
				columnconfigs.add(com.getColumn(i));
			}
			String id = "";
			String name = "";
			for(ColumnConfig columnconfig : columnconfigs){
				if(!columnconfig.isHidden()){
					id += columnconfig.getId() + "@";
					name += columnconfig.getHeader() + "@";
				}
			}
			id = id.substring(20,id.length()-1);
			name = name.substring(6,name.length() - 1);
			Window.open(GWT.getHostPageBaseURL() + "hr_Jsp/employSearch.jsp?id=" + id + "&name=" + name + "&where=" + where, "_blank", "menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes");
		}
	}
}
